package com.baishancloud.log

import com.baishancloud.log.common.entity._
import com.baishancloud.log.common.util.{ArrayUtil, ExternalDataFetchUtil, TimeUtil}
import org.apache.kafka.common.serialization.StringSerializer
import org.junit.Test

import java.lang
import java.time.format.DateTimeFormatter
import java.time.{LocalDateTime, ZoneOffset}
import scala.collection.JavaConverters.asJavaIterableConverter
import scala.collection.mutable

/**
 * 一些临时测试方法
 *
 * @author ziqiang.wang 
 * @date 2021/10/18 16:59
 */
class AppTestS {


  @Test
  def test1(): Unit = {
    val s = "sink.properties.my.property"
    val temp = s.substring(s.indexOf(46, s.indexOf(".") + 1) + 1)
    println(temp)
  }

  @Test
  def test2(): Unit = {
    val s = "topic1,2"
    println(s.split(",").toList.asJava)
  }


  @Test
  def test4(): Unit = {
    val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
    val value = 1637549256L
    println(LocalDateTime.ofEpochSecond(value, 0, ZoneOffset.ofHours(8)).format(formatter))
  }

  @Test
  def test5(): Unit = {
    println(1637549256262L / 1000)
  }

  @Test
  def test6(): Unit = {
    println(classOf[StringSerializer].getName)
    println(classOf[StringSerializer].getTypeName)
    println(classOf[StringSerializer].getSimpleName)
    println(classOf[StringSerializer].getCanonicalName)
  }

  @Test
  def test7(): Unit = {
    val key = "sink1.other.time.out"
    val temp: String = key.substring(key.indexOf(".") + 1)
    println(temp.substring(temp.indexOf(".") + 1))
  }


  @Test
  def test9(): Unit = {
    val a: Array[lang.Long] = Array[lang.Long](1, 3, 5, 7, 8, 12, 23, 56, 78, 90, 112, 345, 667, 678)
    val value: lang.Long = 667
    val index = ArrayUtil.binarySearch(a, value, "[]")
    println(s"index: ${index}, 对应值为：${
      if (index == -1) {
        "未找到"
      } else a(index)
    }")
  }

  @Test
  def test10(): Unit = {
    val a: Array[lang.Long] = new Array[lang.Long](1000000)
    for (i <- 0 until 1000000) {
      a.update(i, i)
    }
    val value: lang.Long = 933499
    val index = ArrayUtil.binarySearch(a, value, "=")
    println(s"index: ${index}, 对应值为：${
      if (index == -1) {
        "未找到"
      } else a(index)
    }")
  }

  @Test
  def test11(): Unit = {
    val nodeInfo: mutable.Map[String, NodeEntity] = mutable.Map[String, NodeEntity]()
    ExternalDataFetchUtil.nodeInfoFetch(nodeInfo)
    println()
  }

  @Test
  def test111(): Unit = {
    val nodeInfo: mutable.Map[String, NodeEntity] = mutable.Map[String, NodeEntity]()
    ExternalDataFetchUtil.nodeInfoFetchFromFile(nodeInfo)
    println()
  }

  @Test
  def test12(): Unit = {
    val typeModuleInfo: mutable.Map[String, mutable.Set[Int]] = mutable.Map[String, mutable.Set[Int]]()
    ExternalDataFetchUtil.typeModuleInfoFetch(typeModuleInfo)
    println()
  }

  @Test
  def test121(): Unit = {
    val typeModuleInfo: mutable.Map[String, mutable.Set[Int]] = mutable.Map[String, mutable.Set[Int]]()
    ExternalDataFetchUtil.typeModuleInfoFetchFromFile(typeModuleInfo)
    println()
  }

  @Test
  def test13(): Unit = {
    val serviceTypeInfo: mutable.Map[String, Byte] = mutable.Map[String, Byte]()
    ExternalDataFetchUtil.serviceTypeInfoFetch(serviceTypeInfo)
    val serviceTypeInfoNot0: mutable.Map[String, Byte] = mutable.Map[String, Byte]()
    serviceTypeInfo.foreach(entry => {
      if (entry._2 != 0) {
        serviceTypeInfoNot0.put(entry._1, entry._2)
      }
    })
    println()
  }

  @Test
  def test131(): Unit = {
    val serviceTypeInfo: mutable.Map[String, Byte] = mutable.Map[String, Byte]()
    ExternalDataFetchUtil.serviceTypeInfoFetchFromFile(serviceTypeInfo)
    val serviceTypeInfoNot0: mutable.Map[String, Byte] = mutable.Map[String, Byte]()
    serviceTypeInfo.foreach(entry => {
      if (entry._2 != 0) {
        serviceTypeInfoNot0.put(entry._1, entry._2)
      }
    })
    println()
  }

  @Test
  def test32(): Unit = {
    println(TimeUtil.longToString(TimeUtil.timeAtLong(System.currentTimeMillis() / 1000, 60000)))
  }

  @Test
  def test33(): Unit = {
    println(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
    println(TimeUtil.timeAtString(1646150400000L, 24 * 3600 * 1000).substring(0, 11))
    println(TimeUtil.timeAtString(System.currentTimeMillis(), 3600 * 1000))
    println(TimeUtil.timeAtString(System.currentTimeMillis(), 600 * 1000))
    println(TimeUtil.timeAtString(System.currentTimeMillis(), 300 * 1000))
    println(TimeUtil.timeAtString(System.currentTimeMillis(), 60 * 1000))
  }

  @Test
  def test34(): Unit = {
    println(IspEntity.DEFAULT)
  }

  @Test
  def test35(): Unit = {
    val array = new Array[Byte](4)
    println(array.mkString("Array(", ", ", ")"))
    println(new String(array))
  }


  @Test
  def testSvg(): Unit = {
    val svgInfo: mutable.Map[String, String] = mutable.Map[String, String]()
    ExternalDataFetchUtil.svgInfoFetch(svgInfo)
    println(svgInfo)
  }

}






















